﻿/// <reference path="~/flyAdmin/scripts/vsdoc.js" />
(function ($) {
    flyCms.SetRole = $.Class({
        base: flyCms.FormBase,
        constructor: function () {
            this.createMembers();
            this.initEvents();
        },
        save: function (isAddTo) {
            var roleIds = this.roleTree.getCheckItems().select("o=>o.id").join(',');
            if (!roleIds.length) {
                $.alert("请选择角色！");
                return;
            }

            $.post(location.href, {
                RoleIDs: roleIds,
                IsAddTo: !!isAddTo
            }, function (res) {
                if (common.getAjaxResult(res))
                    window.open("list", "_self")
            });
            return false;
        },
        initEvents: function () {
            var me = this
            this.btnAddTo.click(this.save, this, true)
            this.btnReplace.click(this.save, this, false)
        },
        createRoleTree: function () {
            this.roleTree = new fly.mini.Tree({
                checkMode: fly.mini.checkMode.multi,
                selectionMode: fly.mini.selectionMode.none,
                checkEvents: { panel: 'click' },
                items: roles
            });
            this.roleTree.render(this.treeContainer[0]);
        },
        createMembers: function () {
            this.treeContainer = $("#treeContainer");
            this.form = $("form")
            this.createRoleTree();
            this.btnAddTo = $("#btn-addTo");
            this.btnReplace = $("#btn-replace")
            this.userIDs = $.getRequest("ids").split(',');
            if (this.userIDs.length < 2) {
                this.btnAddTo.hide();
                this.btnReplace.text("保存");
            }
        }
    });
    flyCms.page = new flyCms.SetRole()
})(fly)